// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import { Facade } from "../../../libs/lightMVC/core/Facade";
import HttpUtils from "../../../libs/lightMVC/util/HttpUtils";
import API from "../../API";
import PlayerModel from "../../model/PlayerModel";

const {ccclass, property} = cc._decorator;

@ccclass
export default class GertGallery extends cc.Component {


    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}

    // update (dt) {}
    jumpUrl()
    {
        
        let player = Facade.getInstance().getModel(PlayerModel).getPlayer();
        let param = {

            uid: player.uid,
            wechat_id : player.wechatid
        }

        HttpUtils.Post(API.wechat_bind_user, param, function (err: string, res: string) {

            if (!err) {
                
                let t_response = JSON.parse(res);
                if(t_response.code== 200){
                    if(confirm("是否跳转到你的美术馆")){
                        // console.log("跳转");
                         history.go(-100);
             
                         let url = API.my_gallery+player.openid;
                         window.location.replace(url);
         
                     }
                     else{
                         history.go(-100);
                         window.location.reload();
                        // console.log("关闭");
                     }
                }
                else{
                    alert("领取失败");
                }
               
               
            }
        })
        

       
    }
}
